package com.baidu.data.mapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import com.baidu.pojo.Cart;
import com.mongodb.BasicDBObject;

@Repository
public class MongoDao {
	
			@Autowired
			private MongoTemplate mongoTemplate;

			public Cart getCartById(String remoteAddr) {
				return mongoTemplate.findOne(new Query().addCriteria(Criteria.where("_id").is(remoteAddr)), Cart.class);
			}

			public void saveCart(Cart cart) {
				mongoTemplate.save(cart);
			}

			public Cart getCartList(String remoteAddr) {
				Cart cart = mongoTemplate.findOne(new Query().addCriteria(Criteria.where("_id").is(remoteAddr)), Cart.class,"cart");
				System.out.println(cart);
				return cart ;
			}

			public void del(String id) {
				 BasicDBObject doc = new BasicDBObject(); 
				 doc.put("id", id);
				mongoTemplate.remove(doc);
			}

		

		

			
			
			
}
